package com.xw.comm.entity.map;

import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiongwei_vendor
 * @date 2021/10/12 19:10
 */
public class BackgroundTreeNode {

    private String mapObjectId;
    private String mapName;

    /**
     * 上级节点
     */
    BackgroundTreeNode proTreeNode;

    /**
     * 子节点
     */
    List<BackgroundTreeNode> list = new ArrayList<BackgroundTreeNode>();

    public String getMapObjectId() {
        return mapObjectId;
    }

    public void setMapObjectId(String mapObjectId) {
        this.mapObjectId = mapObjectId;
    }

    public String getMapName() {
        return mapName;
    }

    public void setMapName(String mapName) {
        this.mapName = mapName;
    }

    public BackgroundTreeNode getProTreeNode() {
        return proTreeNode;
    }

    public void setProTreeNode(BackgroundTreeNode proTreeNode) {
        this.proTreeNode = proTreeNode;
    }

    /**
     * 添加子集
     * @param backgroundTreeNode 子树
     */
    public void addBackgroundTreeNode(BackgroundTreeNode backgroundTreeNode){
        list.add(backgroundTreeNode);
        backgroundTreeNode.proTreeNode = this;
    }

    public List<BackgroundTreeNode> getList() {
        return list;
    }

    public BackgroundTreeNode getBackgroundTreeNode(int index){
        if (list.size() < index){
            return null;
        }
        return list.get(index);
    }

    public void removeBackgroundTreeNode(BackgroundTreeNode backgroundTreeNode){
        this.list.remove(backgroundTreeNode);
        backgroundTreeNode.proTreeNode = null;
    }


    @Override
    public String toString() {
        return "BackgroundTreeNode{" +
                "mapObjectId='" + mapObjectId + '\'' +
                ", mapName='" + mapName + '\'' +
                '}';
    }

}
